
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: PlainItem.java 377 2010-03-11 20:50:18Z archie.cobbs $
 */

package org.dellroad.sidekar;

/**
 * A "plain" {@link Item} implementation that does not subclass a user model class
 * and therefore offers no methods for direct field access.
 */
final class PlainItem<T> implements Item<T> {

    private final long id;
    private final Entity<T> entity;

    public PlainItem(long id, Entity<T> entity) {
        this.id = id;
        this.entity = entity;
    }

    public long getSidekarId() {
        return this.id;
    }

    public Entity<T> getSidekarEntity() {
        return this.entity;
    }

    public void sidekarAttach() {
        this.entity.attach(this);
    }

    public void sidekarDetach() {
        this.entity.detach(this);
    }

    public boolean isSidekarAttached() {
        return this.entity.isAttached(this);
    }

    public Item<T> sidekarValidate() {
        this.entity.validate(this);
        return this;
    }
}

